﻿using UnityEngine;
using System.Collections;

public class MyServerItem : MonoBehaviour {
    public UILabel server;
    public UILabel serverId_label;
    public GameObject selectSprite;
    public UILabel userLevel;
    public UILabel userNickName;
    public UISprite serverType;
  
    ProtoBuf.Message.ConfigServerZone zoneInfo;

    public ProtoBuf.Message.ConfigServerZone GetZoneInfo()
    {
        return zoneInfo;
    }

    public void InitServerItem(ProtoBuf.Message.ConfigServerZone info, ProtoBuf.Message.ConfigPlayerServer playerInfo, UIEventListener.VoidDelegate _onClick)
    {
        InitServerItem(info.state, info.globalServerKey, info.serverId, info.name, info.display, info.serverIp, playerInfo.playerName, playerInfo.level.ToString(), _onClick);
        this.zoneInfo = info;

    }

    void InitServerItem(string state, string serverKey, int serverId, string serverName, string display,string serverIp, string nickName, string level, UIEventListener.VoidDelegate _onclick)
    {
        server.text = serverName;
        if (string.IsNullOrEmpty(display))
        {
           
           
            serverId_label.text = serverId + LanguageTool.GetTextNoUpdate(1062);
        }
        else
        {
       
            serverId_label.text = display + LanguageTool.GetTextNoUpdate(1062);
        }
       
        userLevel.text = TableTextBlo.GetText("level") + level;
        userNickName.text = nickName;
        //this.state = state;
        if (state == "normal")//正常
        {
            serverType.spriteName = "UI_denglu_item_hot";
            
        }
        else if (state == "recommend")//新区
        {
            serverType.spriteName = "UI_denglu_item_new";
           
        }
        else if (state == "maintain")//维护
        {
            serverType.spriteName = "";
          
        }
        else if (state == "busy")//爆满
        {
          
            serverType.spriteName = "UI_denglu_item_hot";
        }
        onclick = _onclick;
        selectSprite.GetComponent<UIButton>().disabledColor = Color.white;
    }

    UIEventListener.VoidDelegate onclick;
    public void OnSelectButtonClick()
    {
        onclick(gameObject);
    }
    void OnClick()
    {
        onclick(gameObject);
    }

    public void DestoryGame()
    {
        Destroy(this.gameObject);
    }
}
